
package rosedb.gui;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import riulib.gui.imagelist.ImageListListener;
import riulib.helpers.ScaleImage;

/**
 *
 * @author riu
 */
public class PreviewPanel extends JPanel implements ImageListListener<File>{
    private Image img;
    private OneRoseImageList img_list;

    public PreviewPanel(OneRoseImageList list) {
        img_list = list;
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        if(img!=null){
            g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
        }else{
            g.drawString("Kein Bild", this.getWidth()/2-g.getFontMetrics().stringWidth("Kein Bild")/2, this.getHeight()/2);
        }
    }

    public void imageSelected(int pos) {
        try {
            img = ScaleImage.scale(ImageIO.read(img_list.getImage(pos)), Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().width);
            repaint();
            System.gc();
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }
    }

    public void imageAdded(File i) {
        
    }

    public void imageRemoved(File i) {
        
    }

    public void imageHovered(int pos) {
        
    }

    @Override
    public void imageReplaced(File Old, File New, int pos) {
    }

    @Override
    public void titleChanged(String Old, String New, int pos) {
        
    }

    
}
